package sg.edu.nus.iss.ooad.jass.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Properties;

/**
 *
 * JobAdvertisement value object. This class is value object representing database table
 * JobAdvertisement. This class is intended to be used together with associated DAO object.
 * This class enscapsulates a particular JobAdvertisement.
 *
 * @author Isak Rabin (HT082193M)
 * @version 1.0
 * @since 1.0
 *
 * Development Environment : Netbeans IDE v6.7
 * Name of the File        : JobAdvertisement.java
 * Creation / Modification History
 *         Isak Rabin        20-Sep-2009        Created
 *
 */
public class JobAdvertisement implements IJASSEntity, Serializable {

        private static final long serialVersionUID = 8263477500215529323L;
        //Holds the attributes of JobAdvertisement Entity
        private final String[] JOBADVERTISEMENT_ATTRIBUTES = {"ID", "AdvertiserID", "CompanyID", "StartDate", "FinishDate", "JobTitle", "JobDescription", "JobLocation", "JobStartDate", "CompanyDepartment", "TechnicalSkills", "ManagementSkills", "MinSalary", "MaxSalary", "Deleted", "Withdrawn"};
        /**
         * Persistent Instance variables.
         * This data is directly  mapped to the columns of database table.
         */
        private String id = "";
        private String advertiserID = "";
        private String companyID = "";
        private String startDate = "";
        private String finishDate = "";
        private String jobTitle = "";
        private String jobDescription = "";
        private String jobLocation = "";
        private String jobStartDate = "";
        private String companyDepartment = "";
        private String technicalSkills = "";
        private String managementSkills = "";
        private float minSalary = 0;
        private float maxSalary = 0;
        private String deleted = "1";
        private String withdrawn = "1";
        /**
         * This data holds a reference to another entity (Associations).
         */
        private Collection<Response> response;

        /**
         * Default Contrustor for JobAdvertisement class.
         */
        public JobAdvertisement() {
                response = new ArrayList<Response>();
        }

        /**
         *
         * Constructor of JobAdvertisement class.s
         * @param ID Job Advertisement ID
         * @param name Job Advertisement Name
         * @param companyID String
         */
        public JobAdvertisement(String id, String advertiserID, String companyID,
                String startDate, String finishDate,
                String jobTitle, String jobDescription, String jobLocation, String jobStartDate,
                String companyDepartment, String technicalSkills, String managementSkills,
                float minSalary, float maxSalary,
                String deleted, String withdrawn) {
                this();
                this.id = id;
                this.advertiserID = advertiserID;
                this.companyID = companyID;
                this.startDate = startDate;
                this.finishDate = finishDate;
                this.jobTitle = jobTitle;
                this.jobDescription = jobDescription;
                this.jobLocation = jobLocation;
                this.jobStartDate = jobStartDate;
                this.companyDepartment = companyDepartment;
                this.technicalSkills = technicalSkills;
                this.managementSkills = managementSkills;
                this.minSalary = minSalary;
                this.maxSalary = maxSalary;
                this.deleted = deleted;
                this.withdrawn = withdrawn;
        }

        /**
         * Get the value of Id
         * @return the value of Id
         */
        public String getID() {
                return id;
        }

        /**
         * Set the value of Id
         * @param Id new value of Id
         */
        public void setID(String id) {
                this.id = id;
        }

        /**
         * Get the value of advertiserID
         * @return the value of advertiserID
         */
        public String getAdvertiserID() {
                return advertiserID;
        }

        /**
         * Set the value of advertiserID
         * @param advertiserID new value of advertiserID
         */
        public void setAdvertiserID(String advertiserID) {
                this.advertiserID = advertiserID;
        }

        /**
         * Get the value of companyID
         * @return The String
         */
        public String getCompanyID() {
                return companyID;
        }

        /**
         * Set the value of companyID
         * @param companyID
         */
        public void setCompanyID(String companyID) {
                this.companyID = companyID;
        }

        /**
         * Get the value of startDate
         * @return the value of startDate
         */
        public String getStartDate() {
                return startDate;
        }

        /**
         * Set the value of startDate
         * @param startDate new value of startDate
         */
        public void setStartDate(String startDate) {
                this.startDate = startDate;
        }

        /**
         * Get the value of finishDate
         * @return the value of finishDate
         */
        public String getFinishDate() {
                return finishDate;
        }

        /**
         * Set the value of finishDate
         * @param finishDate new value of finishDate
         */
        public void setFinishDate(String finishDate) {
                this.finishDate = finishDate;
        }

        /**
         * Get the value of jobTitle
         * @return the value of jobTitle
         */
        public String getJobTitle() {
                return jobTitle;
        }

        /**
         * Set the value of jobTitle
         * @param jobTitle new value of jobTitle
         */
        public void setJobTitle(String jobTitle) {
                this.jobTitle = jobTitle;
        }

        /**
         * Get the value of jobDescription
         * @return the value of jobDescription
         */
        public String getJobDescription() {
                return jobDescription;
        }

        /**
         * Set the value of jobDescription
         * @param jobDescription new value of jobDescription
         */
        public void setJobDescription(String jobDescription) {
                this.jobDescription = jobDescription;
        }

        /**
         * Get the value of jobLocation
         * @return the value of jobLocation
         */
        public String getJobLocation() {
                return jobLocation;
        }

        /**
         * Set the value of jobLocation
         * @param jobLocation new value of jobLocation
         */
        public void setJobLocation(String jobLocation) {
                this.jobLocation = jobLocation;
        }

        /**
         * Get the value of jobStartDate
         * @return the value of jobStartDate
         */
        public String getJobStartDate() {
                return jobStartDate;
        }

        /**
         * Set the value of jobStartDate
         * @param jobStartDate new value of jobStartDate
         */
        public void setJobStartDate(String jobStartDate) {
                this.jobStartDate = jobStartDate;
        }

        /**
         * Get the value of companyDepartment
         * @return the value of companyDepartment
         */
        public String getCompanyDepartment() {
                return companyDepartment;
        }

        /**
         * Set the value of companyDepartment
         * @param companyDepartment new value of companyDepartment
         */
        public void setCompanyDepartment(String companyDepartment) {
                this.companyDepartment = companyDepartment;
        }

        /**
         * Get the value of technicalSkills
         * @return the value of technicalSkills
         */
        public String getTechnicalSkills() {
                return technicalSkills;
        }

        /**
         * Set the value of technicalSkills
         * @param technicalSkills new value of technicalSkills
         */
        public void setTechnicalSkills(String technicalSkills) {
                this.technicalSkills = technicalSkills;
        }

        /**
         * Get the value of managementSkills
         * @return the value of managementSkills
         */
        public String getManagementSkills() {
                return managementSkills;
        }

        /**
         * Set the value of managementSkills
         * @param managementSkills new value of managementSkills
         */
        public void setManagementSkills(String managementSkills) {
                this.managementSkills = managementSkills;
        }

        /**
         * Get the value of minSalary
         * @return the value of minSalary
         */
        public float getMinSalary() {
                return minSalary;
        }

        /**
         * Set the value of minSalary
         * @param minSalary new value of minSalary
         */
        public void setMinSalary(float minSalary) {
                this.minSalary = minSalary;
        }

        /**
         * Get the value of maxSalary
         * @return the value of maxSalary
         */
        public float getMaxSalary() {
                return maxSalary;
        }

        /**
         * Set the value of maxSalary
         * @param maxSalary new value of maxSalary
         */
        public void setMaxSalary(float maxSalary) {
                this.maxSalary = maxSalary;
        }

        /**
         * Get the value of deleted
         * @return the value of deleted
         */
        public String getDeleted() {
                return deleted;
        }

        /**
         * Set the value of deleted
         * @param deleted new value of deleted
         */
        public void setDeleted(String deleted) {
                this.deleted = deleted;
        }

        /**
         * 
         * @return
         */
        public boolean isDeleted() {
                if (deleted.equals("1")) {
                        return false;
                } else {
                        return true;
                }
        }


        /**
         * Get the value of withdrawn
         * @return the value of withdrawn
         */
        public String getWithdrawn() {
                return withdrawn;
        }

        /**
         * Set the value of withdrawn
         * @param withdrawn new value of withdrawn
         */
        public void setWithdrawn(String withdrawn) {
                this.withdrawn = withdrawn;
        }

        /**
         *
         * @return
         */
        public boolean isWithdrawn() {
                if (withdrawn.equals("1")) {
                        return false;
                } else {
                        return true;
                }
        }

        /**
         * Get the value of response
         * @return the value of response
         */
        public Collection<Response> getResponse() {
                return response;
        }

        /**
         * Set the value of response
         * @param response new value of response
         */
        public void setResponse(Collection<Response> response) {
                this.response = response;
        }


        /**
         * Converts Properties to JobAdvertisement entity.
         * @param properties
         * @return
         */
        public Hashtable<String, IJASSEntity> fromJASSPropertiesFormat(Properties properties) {
                Hashtable<String, IJASSEntity> jobadvertisements = new Hashtable<String, IJASSEntity>();

                String sTotalRecords = properties.getProperty("NumOfItems", "0");
                int iTotalRecords = Integer.parseInt(sTotalRecords);
                for (int i = 1; i <= iTotalRecords; i++) {
                        String[] values = new String[JOBADVERTISEMENT_ATTRIBUTES.length];
                        for (int j = 0; j < JOBADVERTISEMENT_ATTRIBUTES.length; j++) {
                                values[j] = properties.getProperty(JOBADVERTISEMENT_ATTRIBUTES[j] + String.valueOf(i));
                        }

                        float fMinSalary = Float.parseFloat(values[12]);
                        float fMaxSalary = Float.parseFloat(values[13]);

                        JobAdvertisement jobadvertisement = new JobAdvertisement(values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7], values[8], values[9], values[10], values[11], fMinSalary, fMaxSalary, values[14], values[15]);
                        jobadvertisements.put(values[0], jobadvertisement);
                }

                return jobadvertisements;
        }

        /**
         * Converts JobAdvertisement entity to Properties Format.
         * @param collections
         * @return
         */
        public Properties toJassPropertiesFormat(Collection<IJASSEntity> collections) {
                Properties properties = new Properties();

                int count = 0;
                for (Iterator<IJASSEntity> i = collections.iterator(); i.hasNext();) {
                        count = count + 1;
                        JobAdvertisement jobadvertisement = (JobAdvertisement) i.next();
                        properties.setProperty(JOBADVERTISEMENT_ATTRIBUTES[0] + String.valueOf(count), jobadvertisement.getID());
                        properties.setProperty(JOBADVERTISEMENT_ATTRIBUTES[1] + String.valueOf(count), jobadvertisement.getAdvertiserID());
                        properties.setProperty(JOBADVERTISEMENT_ATTRIBUTES[2] + String.valueOf(count), jobadvertisement.getCompanyID());
                        properties.setProperty(JOBADVERTISEMENT_ATTRIBUTES[3] + String.valueOf(count), jobadvertisement.getStartDate());
                        properties.setProperty(JOBADVERTISEMENT_ATTRIBUTES[4] + String.valueOf(count), jobadvertisement.getFinishDate());
                        properties.setProperty(JOBADVERTISEMENT_ATTRIBUTES[5] + String.valueOf(count), jobadvertisement.getJobTitle());
                        properties.setProperty(JOBADVERTISEMENT_ATTRIBUTES[6] + String.valueOf(count), jobadvertisement.getJobDescription());
                        properties.setProperty(JOBADVERTISEMENT_ATTRIBUTES[7] + String.valueOf(count), jobadvertisement.getJobLocation());
                        properties.setProperty(JOBADVERTISEMENT_ATTRIBUTES[8] + String.valueOf(count), jobadvertisement.getJobStartDate());
                        properties.setProperty(JOBADVERTISEMENT_ATTRIBUTES[9] + String.valueOf(count), jobadvertisement.getCompanyDepartment());
                        properties.setProperty(JOBADVERTISEMENT_ATTRIBUTES[10] + String.valueOf(count), jobadvertisement.getTechnicalSkills());
                        properties.setProperty(JOBADVERTISEMENT_ATTRIBUTES[11] + String.valueOf(count), jobadvertisement.getManagementSkills());
                        properties.setProperty(JOBADVERTISEMENT_ATTRIBUTES[12] + String.valueOf(count), String.valueOf(jobadvertisement.getMinSalary()));
                        properties.setProperty(JOBADVERTISEMENT_ATTRIBUTES[13] + String.valueOf(count), String.valueOf(jobadvertisement.getMaxSalary()));
                        properties.setProperty(JOBADVERTISEMENT_ATTRIBUTES[14] + String.valueOf(count), jobadvertisement.getDeleted());
                        properties.setProperty(JOBADVERTISEMENT_ATTRIBUTES[15] + String.valueOf(count), jobadvertisement.getWithdrawn());
                }
                properties.setProperty("NumOfItems", String.valueOf(collections.size()));

                return properties;
        }

        @Override
        public String toString() {
                return super.toString();
        }
}
